package com.zy.mc_module.ui.setting.setpay;

import android.content.Context;

import com.zy.mc_module.mvp.base.BasePresenter;
import com.zy.mc_module.mvp.bean.BaseBean;
import com.zy.mc_module.utils.retrofit.RxObserver;
import com.zy.mc_module.utils.retrofit.RxTransform;
import com.zy.mc_module.utils.retrofit.error.ThdException;

/**
 * author : dq
 * date   : 19/4/16
 * desc   :
 */
public class SetPayPresenter extends BasePresenter<SetPayContract.View> {
    private SetPayModel model;

    public SetPayPresenter() {
        model = new SetPayModel();
    }

    /***
     * 设置支付密码
     */
    public void setPayPwd(Context context, String pwd) {
        model.setPayPwd(pwd).compose(RxTransform.schedule())
                .subscribe(new RxObserver<BaseBean>(this, context, true) {
                    @Override
                    protected void onBaseNext(BaseBean bean) {
                        getView().onSuccess((Boolean) bean.data, "设置支付密码失败");
                    }

                    @Override
                    protected void onBaseError(ThdException e) {
                        getView().onError(e);
                    }
                });
    }

    /***
     * 校验支付密码
     */
    public void checkPayPwd(Context context, String pwd) {
        model.checkPayPwd(pwd).compose(RxTransform.schedule())
                .subscribe(new RxObserver<BaseBean>(this, context, true) {
                    @Override
                    protected void onBaseNext(BaseBean bean) {
                        getView().checkSuccess((Boolean) bean.data, "原支付密码错误，请重新输入");
                    }

                    @Override
                    protected void onBaseError(ThdException e) {
                        getView().onError(e);
                    }
                });
    }

    /***
     * 修改支付密码
     */
    public void changePayPwd(Context context, String pwd, String newPwd) {
        model.changePayPwd(pwd, newPwd).compose(RxTransform.schedule())
                .subscribe(new RxObserver<BaseBean>(this, context, true) {
                    @Override
                    protected void onBaseNext(BaseBean bean) {
                        getView().onSuccess((Boolean) bean.data, "修改支付密码失败");
                    }

                    @Override
                    protected void onBaseError(ThdException e) {
                        getView().onError(e);
                    }
                });
    }

    /***
     * 忘记支付密码
     */
    public void forgetPayPwd(Context context, String code, String newPwd) {
        model.forgetPayPwd(code, newPwd).compose(RxTransform.schedule())
                .subscribe(new RxObserver<BaseBean>(this, context, true) {
                    @Override
                    protected void onBaseNext(BaseBean bean) {
                        getView().forgetSuccess((Boolean) bean.data);
                    }

                    @Override
                    protected void onBaseError(ThdException e) {
                        getView().onError(e);
                    }
                });
    }
}
